package com.livesource.client.webservices.project;

import com.google.gwt.http.client.Request;
import com.google.gwt.http.client.RequestBuilder;
import com.google.gwt.http.client.RequestCallback;
import com.google.gwt.http.client.RequestException;
import com.google.gwt.http.client.Response;
import com.livesource.client.model.project.Project;

/**
 * Communicates via REST Web Service
 * 
 */
public class RequestSaveProject {

	// http://jsonpfy.livesourceagile.appspot.com/PutService?kind=Project
	// &ID=AmazonTravelLog
	// &fieldsKind=String&fieldsName=repositoryType&fieldsValue=GitHub
	// &fieldsKind=String&fieldsName=repositoryURL&fieldsValue=

	private static String url = "http://jsonpfy.livesourceagile.appspot.com/PutService";

	public static void sendPostRequest(Project project) {

		String urlSave = url + "?kind=Project" + "&ID="
				+ project.getProjectID()
				+ "&fieldsKind=String&fieldsName=repositoryType&fieldsValue="
				+ project.getRepositoryType()
				+ "&fieldsKind=String&fieldsName=repositoryURL&fieldsValue="
				+ project.getRepositoryURL();

		RequestBuilder builder = new RequestBuilder(RequestBuilder.POST,
				urlSave);

		// builder.setRequestData(requestData);

		try {
			Request request = builder.sendRequest(null, new RequestCallback() {

				public void onError(Request request, Throwable exception) {
					// displayError("Couldn't retrieve JSON");
				}

				public void onResponseReceived(Request request,
						Response response) {
					if (200 == response.getStatusCode()) {
						// updateTable(asArrayOfStockData(response.getText()));
					} else {
						// displayError("Couldn't retrieve JSON ("
						// + response.getStatusText() + ")");
					}
				}
			});
		} catch (RequestException e) {
			// displayError("Couldn't retrieve JSON");
		}

	}
}